<template>
	<view class="web_view">
		<web-view v-if="view" :webview-styles="{progress: {
			color: '#FB652E'
		}}" :src="url || oilurl" @message="message" @onPostMessage="onPostMessage"></web-view>
	</view>
</template>

<script lang="ts" setup>
	import {
		onLoad,
		onUnload
	} from '@dcloudio/uni-app'
	import {
		computed,
		ref
	} from 'vue';
	import useStore from '../../stores/index'
	import { navTo } from '../../utils/common';

	const url = ref('')
	const view = ref(true)
	const store = useStore()
	const oilurl = computed(() => {
		return store.oilUrl
	})
	onLoad((option) => {
		url.value = option.url
	})
	const message = (data : { detail : { data : any[] } }) => {
		console.log(data, 'message');
		if (data?.detail?.data || data.detail.data[0]?.action === 'back') {
			view.value = false
			navTo('/pages/withdrawal/business', 'redirectTo')
		}
	}

	const onPostMessage = (message) => {
		console.log(message, 'adatatata');
	}

	onUnload(() => {
		store.setOilUrl('')
	})
</script>

<style lang="scss" scoped>
	.web_view {
		width: 100%;
		height: 100vh;
		overflow: hidden;
	}
</style>